package com.chaihu.user.api;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chaihu.bean.dto.user.UserDto;
import com.chaihu.bean.in.user.userinfo.QueryUserIn;
import com.chaihu.bean.out.user.userinfo.QueryUserOut;
import com.chaihu.bean.result.ResponseResult;
import com.chaihu.intf.user.QueryUsersService;
import com.chaihu.user.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/test")
public class TestApi {

    @Autowired
    private QueryUsersService queryUsersService;
    @Autowired
    private UserDao userDao;

    @RequestMapping(value = "/get0", method = RequestMethod.GET)
    public ResponseEntity<Void> get2() {
        // mybatis plus 增删改查
        UserDto userDto = new UserDto();
        userDto.setName("李四");
        userDto.setUserId("12111111");
        userDto.setLevelCd("01");
        userDao.insert(userDto);

        LambdaUpdateWrapper<UserDto> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
        lambdaUpdateWrapper.eq(UserDto::getName, "李四");
        userDto.setMobile("lsdfsdl");
        userDao.update(userDto, lambdaUpdateWrapper);


        LambdaQueryWrapper<UserDto> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(UserDto::getName, "李四");
        userDao.delete(lambdaQueryWrapper);

        LambdaQueryWrapper<UserDto> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
        lambdaQueryWrapper2.eq(UserDto::getName, "李四");
        userDao.selectList(lambdaQueryWrapper2);

//        ResponseResult<List<QueryUserOut>> queryUserOutResponseResult = queryUsersService.queryUsers(new QueryUserIn());
//        System.out.println(JSON.toJSONString(queryUserOutResponseResult));
//        System.out.println("get");
        return null;
    }
}
